//
//  ASTabBarController.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/27.
//

#import "ASTabBarController.h"
#import "ASHomeViewController.h"
#import "ASUserCenterController.h"

@interface ASTabBarController () <UITabBarControllerDelegate>

@end

@implementation ASTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //    [[UITabBar appearance]setTintColor:MAIN_NAV_COLOR];
    //    [[UITabBar appearance]setUnselectedItemTintColor:[UIColor colorWithHexString:@"A1A7B2"]];
    [UITabBar appearance].translucent = NO;
    [[UITabBar appearance]setBarTintColor:MAIN_NAV_COLOR];
    self.delegate = self;
        
    //首页
    ASHomeViewController * homeVC = [[ASHomeViewController alloc ] init ];
    UINavigationController *navHomeVC = [[UINavigationController alloc]initWithRootViewController:homeVC];
    homeVC.tabBarItem.title = @"首页";
    homeVC.tabBarItem.image = [[UIImage imageNamed:@"home_sy_p"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_sy_n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [homeVC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#CCCCCC"],
                                               NSForegroundColorAttributeName,
                                               nil] forState:UIControlStateNormal];
    [homeVC.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#322728"],
                                               NSForegroundColorAttributeName,
                                               nil] forState:UIControlStateSelected];
    homeVC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2);
    

    //个人中心
    ASUserCenterController * mine = [[ASUserCenterController alloc ] init ];
    UINavigationController *navMine = [[UINavigationController alloc]initWithRootViewController:mine];
    mine.tabBarItem.title = @"我的";
    mine.tabBarItem.image = [[UIImage imageNamed:@"home_wd_p"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mine.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_wd_n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [mine.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#CCCCCC"],
                                                   NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateNormal];
    [mine.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#322728"],
                                                   NSForegroundColorAttributeName,
                                                   nil] forState:UIControlStateSelected];
    mine.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2);

    self.viewControllers = @[navHomeVC,navMine];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    if (item.title.length > 1) {
        NSDictionary *dict = @{@"bottom_navigation" : item.title};
        [MobClick event:@"comprehensive" attributes:dict];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
